#include "Vector.h"
#include <vector>
#include <algorithm>
#include <string>

template <class T>
void PrintVector(const T &t)
{
    for (auto &x : t)
    {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

void TestStdVector01()
{

    // n个相同的数构造
    std::vector<int> v(10, 6);

    // 遍历1-下标
    for (size_t i = 0; i < v.size(); i++)
    {
        std::cout << v[i] << " ";
    }
    std::cout << std::endl;

    // 遍历2-迭代器
    std::vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        std::cout << *it << " ";
        it++;
    }
    std::cout << std::endl;

    // 遍历3-范围for
    for (auto &x : v)
    {
        std::cout << x << " ";
    }
    std::cout << std::endl;

    PrintVector(v);
}

void TestWxdVector01()
{
    wxd::vector<int> v1;
    v1.push_back(1);
    PrintVector(v1);
    v1.push_back(2);
    PrintVector(v1);
    v1.push_back(3);
    PrintVector(v1);
    v1.push_back(4);
    PrintVector(v1);
    v1.push_back(4);
    PrintVector(v1);

    v1.pop_back();
    PrintVector(v1);
    v1.pop_back();
    PrintVector(v1);
    v1.pop_back();
    PrintVector(v1);
    v1.pop_back();
    PrintVector(v1);
    v1.pop_back();
    PrintVector(v1);

    v1.pop_back();
    PrintVector(v1);

    const wxd::vector<int> v2(10, 6);
    // v2[0]++;
    PrintVector(v2);
}

void TestWxdVector02()
{
    wxd::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);
    PrintVector(v1);
    wxd::vector<int>::iterator it = v1.begin();
    v1.insert(it, 0);
    PrintVector(v1);
    auto it1 = v1.end();
    v1.insert(it1, 6);
    PrintVector(v1);
}

void TestWxdVector03()
{
    wxd::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);
    PrintVector(v1);
    // 迭代器失效问题
    // 在4前插入0
    wxd::vector<int>::iterator ret_it = std::find(v1.begin(), v1.end(), 4);
    v1.insert(ret_it, 0);
    PrintVector(v1);
}

void TestWxdVector04()
{
    wxd::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);
    PrintVector(v1);
    // v1.erase(v1.begin());
    // PrintVector(v1);
    // v1.erase(v1.end()-1);
    // PrintVector(v1);

    v1.resize(3);
    PrintVector(v1);
    v1.resize(10);
    PrintVector(v1);
}

void TestWxdVector05()
{
    wxd::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);
    PrintVector(v1);
    wxd::vector<int> v2 = v1;
    PrintVector(v2);
    std::cout<<"v1:size:"<<v1.size()<<std::endl;
    std::cout<<"v1:capacity:"<<v1.capacity()<<std::endl;
    std::cout<<"v2:size:"<<v2.size()<<std::endl;
    std::cout<<"v2:capacity:"<<v2.capacity()<<std::endl;
    wxd::vector<int> v3;
    v3 = v1;
    PrintVector(v3);
    std::cout<<"v3:size:"<<v3.size()<<std::endl;
    std::cout<<"v3:capacity:"<<v3.capacity()<<std::endl;
}

void TestWxdVector06()
{
    wxd::vector<int> v1;
    v1.push_back(1);
    v1.push_back(2);
    v1.push_back(3);
    v1.push_back(4);
    v1.push_back(5);
    PrintVector(v1);
    wxd::vector<int> v2(v1.begin(),v1.end());
    PrintVector(v2);
}

void TestWxdVector07()
{
    std::string s1 = "66666666666";
    wxd::vector<std::string> v1;
    v1.push_back(s1);
    v1.push_back(s1);
    v1.push_back(s1);
    v1.push_back(s1);
    PrintVector(v1);
    v1.push_back(s1);
    PrintVector(v1);


}

int main()
{
    // TestStdVector01();
    // TestWxdVector01();
    // TestWxdVector02();
    // TestWxdVector03();
    //TestWxdVector04();
    //TestWxdVector05();
    //TestWxdVector06();
    TestWxdVector07();

    return 0;
}